package com.javasm.controller;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.IndentCriteria;
import com.javasm.domin.vo.IndentGoodsVo;
import com.javasm.domin.vo.IndentVo;
import com.javasm.service.IndentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author longjun
 * @since 2022-01-16
 */
@RestController
@RequestMapping("indent")
@RequiredArgsConstructor//和@Autowired效果一样
public class IndentController extends BaseController {

    private final IndentService indentService;


    @GetMapping("list")
    public AxiosResult<PageResult<IndentVo>> list(IndentCriteria indentCriteria) {

        PageResult<IndentVo> pageList = indentService.searchPage(indentCriteria);
        System.out.println(pageList);
        return AxiosResult.success(pageList);
    }

    @GetMapping("findAllIndent")
    public AxiosResult<List<IndentVo>> IndentList() {
        List<IndentVo> indentVoList = indentService.searchIndentList();
        return AxiosResult.success(indentVoList);
    }


    @DeleteMapping("{id}")
    public AxiosResult<Void> delete(@PathVariable Integer id) {

        return toAxios(indentService.deleteIndentById(id));
    }

    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void>  batchDelete(@PathVariable  List<Long> ids) {
        return toAxios(indentService.deleteIndentByIds(ids));
    }

    @GetMapping("findIndentById/{id}")
    public AxiosResult<IndentVo> findIndentById(@PathVariable Integer id) {

        IndentVo indentVo = indentService.searchIndentById(id);
        return AxiosResult.success(indentVo);
    }




}
